package com.li.kafka.producer;

import org.apache.kafka.clients.producer.Partitioner;
import org.apache.kafka.common.Cluster;

import java.util.Map;

/** 自定义partition负载均衡 */
public class SamplePartition implements Partitioner {
  @Override
  public int partition(
      String s, Object o, byte[] bytes, Object o1, byte[] bytes1, Cluster cluster) {
    String keyStr = o + "";
    String keyInt = keyStr.substring(3);
    Integer key = Integer.parseInt(keyInt);
    return key % 2;
  }

  @Override
  public void close() {}

  @Override
  public void configure(Map<String, ?> map) {}
}
